package com.jubaozan.service.platform.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jubaozan.c3.framework.constants.Constants;
import com.jubaozan.c3.framework.utils.ResultHolder;
import com.jubaozan.c3.framework.utils.ResultStatus;
import com.jubaozan.dao.youme.domain.Store;
import com.jubaozan.service.platform.decorator.StoreDecorator;
import com.jubaozan.service.platform.vo.ScGoodsVO;
import com.jubaozan.feign.platform.vo.StoreVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Auther: chenjingui
 * @Date: 2020/9/21 15:40
 * @Description:
 */
@Api(tags = {"个体平台信息查询接口"}, value = "个体平台信息查询接口")
@RestController
@RequestMapping("/store")
@Validated
public class StoreController {
    @Autowired
    private StoreDecorator storeDecorator;

    @ApiOperation(value = "获取个体平台列表,支持模糊查询个体平台名称")
    @GetMapping(value = "/list")
    public ResultHolder<IPage> queryStore(
            @RequestParam(required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(required = false)String title) {
        Page<Store> page = new Page<>(pageNo, pageSize);
        return ResultHolder.success(storeDecorator.getStoreList(page, title));
    }
    @ApiOperation(value = "个体平台详细信息")
    @GetMapping(value = "/queryStoreDetails")
    public ResultHolder<StoreVO> queryStoreDetails(@RequestParam(value = "id") Long id) {
        return ResultHolder.success(storeDecorator.queryStoreDetails(id));
    }

    @ApiOperation(value = "按照不同条件搜锁审核通过且上架的商品,支持选择个体平台后 通过复选框显示被历史选择")
    @GetMapping(value = "/getGoods")
    public ResultHolder<IPage<ScGoodsVO>> getGoods(@RequestParam(required = false) Long oneCategoryId, @RequestParam(required = false)
            Long supplierId, @RequestParam
            (required = false) String goodsName,
                                                  @RequestParam(required = false, defaultValue = "1") Integer pageNo,
                                                  @RequestParam(required = false, defaultValue = "10") Integer pageSize, @RequestParam(value = "storeId",required =false)Long storeId) {
        return storeDecorator.getGoods(oneCategoryId,supplierId,goodsName,pageNo,pageSize,storeId);
    }
    @ApiOperation(value = "将勾选的商品保存到个体平台中")
    @GetMapping(value = "/saveGoodsToStore")
    public ResultHolder<Boolean> saveGoodsToStore(@RequestHeader(value = Constants.KEY_USERNAME,required = false)
                                                              String
                                                              username,@RequestParam
            (value = "storeId") Long storeId,
            @RequestParam(value = "ids") List<Long> goodsId) {
        if(StringUtils.isEmpty(storeId)||StringUtils.isEmpty(goodsId)){
            return ResultHolder.error(ResultStatus.PARAMETER_ERROR,"入参有为空，请检查！");
        }
        return ResultHolder.success(storeDecorator.saveGoodsToStore(username,storeId,goodsId));
    }
    @ApiOperation(value = "个体平台按照不同条件搜素查询当前自己选中的商品")
    @GetMapping(value = "/getSelectGoods")
    public ResultHolder<IPage<ScGoodsVO>> getSelectGoods(@RequestParam(required = false) Long oneCategoryId,@RequestParam(required = false)
            Long supplierId,@RequestParam
                                                       (required = false) String goodsName,
                                               @RequestParam(required = false, defaultValue = "1") Integer pageNo,
                                               @RequestParam(required = false, defaultValue = "10") Integer pageSize,@RequestParam(value = "storeId")Long storeId) {
        if(StringUtils.isEmpty(storeId)){
            return ResultHolder.error(ResultStatus.PARAMETER_ERROR,"入参storeId为空！");
        }
        return storeDecorator.getSelectGoods(oneCategoryId,supplierId,goodsName,pageNo,pageSize,storeId);
    }
}
